package com.zwk.sta.scheduling;


import com.zwk.base.util.DateUtil;
import com.zwk.sta.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zwk
 * @create 2022/9/2 16:41
 * 定时统计网站数据
 */
@Component
public class ScheduledTask {

    @Autowired
    private DailyService dailyService;

    // 每5秒执行一次
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void test(){
//        System.out.println("执行定时任务测试");
//    }

    // 每天凌晨一点统计前一天的数据
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        dailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
        System.out.println("执行统计数据定时任务");
    }

}
